<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{$system['name']}后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/admin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .layui-form-pane .layui-form-label {
            width: 110px;
            padding: 8px 15px;
            height: 38px;
            line-height: 20px;
            border-width: 0px;
            border-style: none;
            border-radius: 2px 0 0 2px;
            text-align: center;
            background-color: #FBFBFB;
            overflow: hidden;
            box-sizing: border-box;
        }

    </style>
</head>
<body >
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <blockquote class="layui-elem-quote">
        请填写真实客户手机号否则无法提交订单
    </blockquote>
    <form class="layui-form layui-form-pane">

        <div class="layui-form-item">
            <label class="layui-form-label">客户手机号</label>
            <div class="layui-input-block">
                <input type="text" id="cphone" name="cphone" lay-verify="required" placeholder="请输入手机号码" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">订单号</label>
            <div class="layui-input-block">
                <input type="text" id="orderno" name="orderno" lay-verify="required|orderno_unqiue" placeholder="请输入订单号" class="layui-input">
                <tip id="checklabel"></tip>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input type="text" readonly id="cname" name="cname" lay-verify="required"  placeholder="请输入客户名称" class="layui-input">
                <tip> 请填写真实客户手机号,否则客户名称无法获取</tip>
            </div>
        </div>
        {if $admin['admin_id'] == 1}
        <div class="layui-form-item">
            <label class="layui-form-label">客户负责人</label>
            <div class="layui-input-block">
                <select name="pr_user" id="pr_user">
                    <option value="">请选择客户负责人</option>
                    {volist name='userlist' id='vo'}
                    <option value="{$vo.username}">{$vo.username}</option>
                    {/volist}

                </select>
            </div>
        </div>
        {else /}
        <div class="layui-form-item">
            <label class="layui-form-label">客户负责人</label>
            <div class="layui-input-block">
                <input type="text" readonly id="pr_user" name="pr_user" lay-verify="required" value="{$username}" class="layui-input">
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label">业绩</label>
            <div class="layui-input-block">
                <input type="text" id="money" name="money"  placeholder="业绩" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">回款</label>
            <div class="layui-input-block">
                <input type="text" id="return_money" name="return_money"  placeholder="请输入回款金额" class="layui-input">
            </div>
        </div>
        <!--
        <div class="layui-form-item">
            <label class="layui-form-label">运费</label>
            <div class="layui-input-block">
                <input type="text" id="freight" name="freight"  placeholder="请输入运费金额" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" id="kh_username" name="kh_username" value=""  placeholder="请输入用户名" class="layui-input">
            </div>
        </div>
        -->
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入订单备注信息" class="layui-textarea" name="remark"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn"  lay-submit="" lay-filter="submit">提交保存</button>

            </div>
        </div>

    </form>
</div>
{include file="common/foot"/}

<script>
        layui.use(['form', 'layer','jquery'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery;
            $(document).on('change','#cphone',function (){
                //重新查找业务员的客户信息
                var custphone = $("#cphone").val();
                $('#cname').val('');
                var url = "{:url('Order/changeyewu')}";
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    data: {'cphone':custphone},
                    url: url ,//url
                    success: function (result) {
                        //console.log(result);//打印服务端返回的数据(调试用)
                        //alert("修改成功");
                        if (result['msg']['code'] == 0) {
                            $('#checklabel').css('color','red');
                        }else{
                            $('#checklabel').css('color','green');
                            $('#cname').val(result['msg']['custname']);
                            $('#pr_user').val(result['msg']['pr_user']);
                            $('#kh_username').val(result['msg']['kh_username']);
                        }
                        $('#checklabel').html(result['msg']['msg']);


                    },
                    error : function() {
                        alert("异常！");
                    }
                });
            });
            form.verify({
                orderno_unqiue : function(value, item) {
                    var checkResult=false;
                    $.ajax({
                        url: "{:url('Order/verify_orderno')}",
                        type: "POST",dataType:"json",
                        data: {orderno:value},
                        async: false,
                        success: function(res) {
                            if (res.code < 0){
                                checkResult=res.msg;
                            }
                        },
                        error: function() {
                        }
                    });
                    if(checkResult){
                        return checkResult;
                    }
                }
            });
            //监听提交
            form.on('submit(submit)', function(data){

                $.post("{:url('Order/add')}",data.field,function (res) {
                    if (res.code == 0){
                        layer.msg(res.msg,{time:2000},function (){
                            window.parent.location.reload();
                        });
                    }else {
                        layer.msg(res.msg,{time:3000});
                    }

                },'json')

                return false;
            });
        });
</script>
</body>
</html>